package com.atguigu.common.execption;

import com.atguigu.common.ResultCodeEnum;
import lombok.Data;

/**
 * ClassName: GuiguException
 * Package: com.atguigu.common.execption
 * Description:
 *
 * @Author 蹇泽阳
 * @Create 2023/11/13 20:16
 * @Version 1.0
 */
@Data
public class GuiguException extends RuntimeException {
  
  private Integer code;
  
  private String message;
  
  /**
   * 通过状态码和错误消息创建异常对象
   * @param code
   * @param message
   */
  public GuiguException(Integer code, String message) {
    super(message);
    this.code = code;
    this.message = message;
  }
  
  /**
   * 接收枚举类型对象
   * @param resultCodeEnum
   */
  public GuiguException(ResultCodeEnum resultCodeEnum) {
    super(resultCodeEnum.getMessage());
    this.code = resultCodeEnum.getCode();
    this.message = resultCodeEnum.getMessage();
  }
  
  @Override
  public String toString() {
    return "GuliException{" +
        "code=" + code +
        ", message=" + this.getMessage() +
        '}';
  }
}
